package com.sjq.common.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sjq.common.dao.UserDao;
import com.sjq.common.entity.LoginAccount;
import com.sjq.common.entity.User;
import com.sjq.common.exception.ServiceException;
import com.sjq.common.service.UserService;
import com.sjq.common.util.PageResults;

@Service("userService")
public class UserServiceImpl implements UserService{
	
	@Autowired
	private UserDao userDao;
	
	@Override
	public void addUser(User user) {
		if(user==null){
			return;
		}
		userDao.insertUser(user);
	}
	
	@Override
	public void removeUser(String userId) {
		userDao.deleteUserById(userId);
	}

	@Override
	public void modifyUser(User user) {
		if(user==null){
			return;
		}
		userDao.updateUser(user);
	}

	@Override
	public Map<String, Object> findUserById(String userId) throws ServiceException {
		Map<String, Object> map=userDao.selectUserById(userId);
		return map;
	}

	@Override
	public PageResults<?> findUserByPage(int pageNo, int pageSize, User user) throws ServiceException {
		PageResults<?> pageResults=userDao.selectUserByPage(pageNo, pageSize, user);
		return pageResults;
	}

	@Override
	public void modifyByUserpsd(String xyhmm, String userId) {
		userDao.updateByUserpsd(xyhmm, userId);
	}

	@Override
	public void modifyByUserRole(String yhm, String roleid) {
		userDao.updateByUserRole(yhm, roleid);
	}

	@Override
	public LoginAccount getLoginAccountBySfhm(String sfhm) {
		Map<String,Object> map=userDao.selectUserById(sfhm);
		String accountId=sfhm;
		String userId=(String)map.get("JH");
		String userName=(String)map.get("XM");
		String userRole=(String)map.get("ROLEDM");
		String userDwbm=(String)map.get("DWBM");
		String userDwmc=(String)map.get("DWMC");
		String userLxdh=(String)map.get("LXFS");
		String userIp=(String)map.get("");
		LoginAccount la=new LoginAccount(accountId, userId, userName, userRole, userDwbm, userDwmc, userIp, userLxdh);
		return la;
	}


}
